package me.jessyan.mvparms.demo.di.module.integral;

import android.support.v4.content.ContextCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.di.scope.FragmentScope;
import com.jess.arms.utils.ArmsUtils;
import com.jess.arms.widget.CustomPopupWindow;

import javax.inject.Named;

import butterknife.internal.DebouncingOnClickListener;
import dagger.Module;
import dagger.Provides;

import me.jessyan.mvparms.demo.R;
import me.jessyan.mvparms.demo.mvp.contract.integral.GiftDetailsContract;
import me.jessyan.mvparms.demo.mvp.model.integral.GiftDetailsModel;
import me.jessyan.mvparms.demo.utils.PerfectClickListener;


@Module
public class GiftDetailsModule {
    private GiftDetailsContract.View view;

    /**
     * 构建GiftDetailsModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
     *
     * @param view
     */
    public GiftDetailsModule(GiftDetailsContract.View view) {
        this.view = view;
    }

    @ActivityScope
    @Provides
    GiftDetailsContract.View provideGiftDetailsView() {
        return this.view;
    }

    @ActivityScope
    @Provides
    GiftDetailsContract.Model provideGiftDetailsModel(GiftDetailsModel model) {
        return model;
    }

    @ActivityScope
    @Provides
    @Named("deletePop")
    CustomPopupWindow deletePop(){
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_gift_detail_delete,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .defultHeight(ArmsUtils.dip2px(view.getActivity().getApplication(),56))

                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                            contentView.setOnClickListener(new PerfectClickListener() {
                                @Override
                                protected void onNoDoubleClick(View v) {

                                    view.dismissPop();
                                    view.popBackDelete();
                                }
                            });
                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }


    @ActivityScope
    @Provides
    @Named("sureDeletePop")
    CustomPopupWindow sureDeletePop(){
        //确定删除这个过期礼品?
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_gift_detail_sure_delete,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        contentView.findViewById(R.id.pop_start_tv).setOnClickListener(new PerfectClickListener() {

                            @Override
                            protected void onNoDoubleClick(View v) {

                                view.dismissPop();
                                view.popBackSureDelete();
                            }
                        });
                        contentView.findViewById(R.id.pop_end_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.dismissPop();
                            }
                        });

                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }
    @ActivityScope
    @Provides
    @Named("confirmChangePop")
    CustomPopupWindow confirmChangePop(){
        //确定确定兑换此物品?
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_frag_mine_loginout,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        TextView titleTv= contentView.findViewById(R.id.pop_title_tv);
                        titleTv.setText("确定兑换此物品?\n将扣除积分"+view.getUserScore()+" ");
                        titleTv.setTextColor(ContextCompat.getColor(view.getActivity().getApplication(),R.color.color_7A7E95));

                        TextView startTv= contentView.findViewById(R.id.pop_start_tv);
                        startTv.setText("立即兑换");
                        startTv.setOnClickListener(new PerfectClickListener() {

                            @Override
                            protected void onNoDoubleClick(View v) {

                                view.dismissPop();
                                view.popBackConfirmChange();
                            }
                        });
                        TextView endTv = contentView.findViewById(R.id.pop_end_tv);
                        endTv.setText("取消兑换");
                        endTv.setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.dismissPop();
                            }
                        });

                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }
    @ActivityScope
    @Provides
    @Named("successChangePop")
    CustomPopupWindow successChangePop(){
        //确定确定兑换此物品?
        View content = LayoutInflater.from(view.getActivity())
                .inflate(R.layout.pop_gift_success_change,null);
        CustomPopupWindow popupWindow = CustomPopupWindow.builder()
                .isFocus(true)
                .isOutsideTouch(true)
                .isWrap(true)
                .contentView(content)
                .customListener(new CustomPopupWindow.CustomPopupWindowListener() {
                    @Override
                    public void initPopupView(View contentView) {
                        TextView contentTv= contentView.findViewById(R.id.today_score_tv);
                        contentTv.setText("你的兑换码为：32165446\n可在 我的-我的兑换 中查看");
                        contentTv.setTextColor(ContextCompat.getColor(view.getActivity().getApplication(),R.color.color_7A7E95));

                        contentView.findViewById(R.id.sure_tv).setOnClickListener(new PerfectClickListener() {
                            @Override
                            protected void onNoDoubleClick(View v) {
                                view.dismissPop();
                            }
                        });

                    }
                }).build();
        //PopupWindow全屏显示
        popupWindow.setClippingEnabled(false);
        return popupWindow;
    }
}